<?php
    require_once "ScoresUtils.php";
    require_once "Response.php";
    mysql_set_charset("utf8");

    switch($_SERVER["REQUEST_METHOD"]){
        case "GET":
            switch($_GET["command"]){
                case "get_scores":
                    //$resp = new Response();
                    //$resp->responseType = Response::RESPONSE_TYPE_OK;
                    //$resp->responseMessage = getScores($_GET["game_name"]);
                    //echo $resp->getResponseObject(Response::RESPONSE_FORMAT_JSON);
                    echo getScores($_GET["game_name"]);
                    break;
                case "new_game":
                    addNewGame();
                    break;
                case "post_scores":
                    postScores();
                    break;
                default:
                    break;
            }
            break;
        case "POST":
            break;
        default:
            break;
    }

    exit;

    function getScores($name){
        $su = new ScoresUtils();
        return $su->getScores($name);
    }

    function addNewGame(){
        $su = new ScoresUtils();
        echo $su->addNewGame($_GET["game_name"], $_GET["game_hash"]);
    }

    function postScores(){
        $su = new ScoresUtils();
        switch($_GET["new_user"]){
            case "true":
                $su->addScores($_GET);
                break;
            case "false":
                $su->updateScores($_GET);
                break;
            default:
                break;
        }
    }
?>